const dbHelper = require('../../dbhelper/dbhelper');
const projectDbHelper = require('../../dbhelper/projectHelper');
const {
    handleError,
    handleSuccess
} = require('../../utils/handle');

module.exports.projectList = async(ctx, next) => {
    const projectList = await projectDbHelper.queryProjectList();
    if (projectList) {
        handleSuccess({
            ctx,
            message: 'success!',
            result: projectList,
        });
    } else {
        handleError({
            ctx,
            message: 'failed...',
        });
    }
};

module.exports.saveProject = async(ctx, next) => {
    const projectItem = ctx.request.body;
    const res = await projectDbHelper.saveProject(projectItem);
    if (res) {
        handleSuccess({
            ctx,
            message: 'success!',
        });
    } else {
        handleError({
            ctx,
            message: 'failed...',
        });
    }
}